<?php

class ExhibitionsController extends Controller
{
  public $layout='//layouts/main';

	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
		);
	}

  public function actions(){
    return array(
        'captcha'=>array(
            'class'=>'CaptchaExtendedAction',
        ),
    );
  }

	public function accessRules()
	{
		return array(
			array('allow',  // allow all users to perform 'index' and 'view' actions
				'actions'=>array('index','view', 'cec', 'selc', 'captcha', 'create'),
				'users'=>array('*'),
			),
			array('allow', // allow authenticated user to perform 'create' and 'update' actions
				'actions'=>array('create','update'),
				'users'=>array('@'),
			),
			array('allow', // allow admin user to perform 'admin' and 'delete' actions
				'actions'=>array('admin','delete'),
				'users'=>array('admin'),
			),
			array('deny',  // deny all users
				'users'=>array('*'),
			),
		);
	}

	public function actionCreate()
	{
		$exhibition = new Exhibitions('frontend');

    if(isset($_POST['Exhibitions']))
    {
      $exhibition->attributes = $_POST['Exhibitions'];
      if($exhibition->save('frontend'))
      {
        Yii::app()->user->setFlash('success', 'Success');
        Yii::app()->user->setFlash('content', 'You have successfully register to our exhibitions.');
        $this->redirect('index');
      }
    }
    $this->render('index', array(
      'exhibition' => $exhibition,
    ));
	}

	public function actionIndex()
	{
    $exhibition = new Exhibitions;
		$this->render('index', array(
      'exhibition' => $exhibition,
    ));
	}
}